home *** CD-ROM | disk | FTP | other *** search
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
- <html>
- <head>
- <title>Foreach come controllo</title>
- </head>
- <body>
- <h4>Compila tutti i campi:</h4><p>
- <form action="check.php" method="post">
- <input name="nome" type="text" size="20"> Nome<p>
- <input name="cognome" type="text" size="20"> Cognome<p>
- <input name="citt" type="text" size="20"> Cittα<p>
- <input type="submit" value="invia">
- </form>
- <?php
- if (!isset($_POST['nome'])) {
- // serve solo alla prima chiamata della pagina
- die ("<p><h3>Tutti i campi vanno obbligatoriamente compilati</h3>");
- }
- foreach ($_POST as $ctr) {
- // foreach ci consente di controllare tutto l'array $_POST
- if (trim($ctr)==""){
- // trim toglie gli spazi vuoti eventualmente presenti in $ctr
- die ("<p><h3>Tutti i campi vanno obbligatoriamente compilati</h3>");
- }
- }
- echo "<p><h4>ciao ".$_POST['nome']." ".$_POST['cognome'].", vivi a ".$_POST['citt'].". Come stai?</h4>";
-
- ?>
- </body>
- </html>
-